package com.fjc.service;

import com.fjc.base.ResponseObject;
import com.fjc.dao.AttendLogDao;
import com.fjc.domain.AttendLog;
import com.fjc.domain.AttendLogExample;
import com.fjc.domain.QueryModel;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by fjc on 2018/9/15.
 */
@Service
public class AttendService {
    @Autowired
    private AttendLogDao attendLogDao;

    public ResponseObject sbdk(AttendLog attendLog){
        attendLogDao.insertSelective(attendLog);
        return new ResponseObject(00,"打卡成功");
    }

    public List<AttendLog> getDk(QueryModel queryModel){
        PageHelper.startPage(queryModel.getPage(),queryModel.getLimit());
        AttendLogExample attendLogExample = new AttendLogExample();
        AttendLogExample.Criteria criteria = attendLogExample.createCriteria();

        if(queryModel.getStart() != null){
            criteria.andAttendEveningGreaterThan(queryModel.getStart());
        }

//        if(queryModel.getEnd() != null){
//            criteria.andAttendEveningLessThan(queryModel.getEnd());
//        }

//        criteria.andAttendStatusEqualTo((Byte) queryModel.getStatus());

        List<AttendLog> list = attendLogDao.selectByExample(attendLogExample);

        return list;
    }


    public ResponseObject save(AttendLog attendLog){
        attendLogDao.updateByPrimaryKeySelective(attendLog);
        return new ResponseObject(00,"成功");
    }

    public ResponseObject del(AttendLog attendLog){
        attendLogDao.deleteByPrimaryKey(attendLog.getId());
        return new ResponseObject(00,"成功");
    }
}
